# Author: williamjcm <w.jcm59@gmail.com>
# Contributor: mosra <mosra@centrum.cz>
# Based on the magnum-plugins Arch Linux PKGBUILD maintained by xyproto and the MSYS2/MinGW PKGBUILD templates

_realname=magnum-plugins
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2019.10
pkgrel=1
pkgdesc='Plugins for the Magnum C++11/C++14 graphics engine'
arch=('any')
url='https://magnum.graphics/'
license=('MIT')
depends=("${MINGW_PACKAGE_PREFIX}-magnum>=$pkgver"
         "${MINGW_PACKAGE_PREFIX}-assimp"
         "${MINGW_PACKAGE_PREFIX}-devil"
         "${MINGW_PACKAGE_PREFIX}-faad2"
         "${MINGW_PACKAGE_PREFIX}-freetype"
         "${MINGW_PACKAGE_PREFIX}-glslang"
         "${MINGW_PACKAGE_PREFIX}-harfbuzz"
         "${MINGW_PACKAGE_PREFIX}-libjpeg-turbo"
         "${MINGW_PACKAGE_PREFIX}-libpng"
         "${MINGW_PACKAGE_PREFIX}-spirv-tools"
         "${MINGW_PACKAGE_PREFIX}-libwebp")
makedepends=("${MINGW_PACKAGE_PREFIX}-cmake" "${MINGW_PACKAGE_PREFIX}-ninja" 'git')
# The .tar.gz / .zip download contains symlinks, making tar and unzip on
# Windows grumpy because dangling symlinks are created. Could be fixed by
# manually extracting everything except symlinks, but that's hard to maintain.
# Downloading a Git tag works.
source=("${_realname}-${pkgver}"::"git+https://github.com/mosra/magnum-plugins.git#tag=v$pkgver")
sha1sums=('SKIP')

build() {
    mkdir -p "${srcdir}"/build-${CARCH} && cd "${srcdir}"/build-${CARCH}

    declare -a extra_config
    if check_option "debug" "n"; then
        extra_config+=("-DCMAKE_BUILD_TYPE=Release")
    else
        extra_config+=("-DCMAKE_BUILD_TYPE=Debug")
    fi

    MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
        ${MINGW_PREFIX}/bin/cmake \
            -G'Ninja' \
            -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
            -DMAGNUM_WITH_ASSIMPIMPORTER=ON \
            -DMAGNUM_WITH_ASTCIMPORTER=ON \
            -DMAGNUM_WITH_BASISIMAGECONVERTER=OFF \
            -DMAGNUM_WITH_BASISIMPORTER=OFF \
            -DMAGNUM_WITH_BCDECIMAGECONVERTER=ON \
            -DMAGNUM_WITH_CGLTFIMPORTER=ON \
            -DMAGNUM_WITH_DDSIMPORTER=ON \
            -DMAGNUM_WITH_DEVILIMAGEIMPORTER=ON \
            -DMAGNUM_WITH_DRFLACAUDIOIMPORTER=ON \
            -DMAGNUM_WITH_DRMP3AUDIOIMPORTER=ON \
            -DMAGNUM_WITH_DRWAVAUDIOIMPORTER=ON \
            -DMAGNUM_WITH_ETCDECIMAGECONVERTER=ON \
            -DMAGNUM_WITH_FREETYPEFONT=ON \
            -DMAGNUM_WITH_GLSLANGSHADERCONVERTER=ON \
            -DMAGNUM_WITH_GLTFIMPORTER=ON \
            -DMAGNUM_WITH_GLTFSCENECONVERTER=ON \
            -DMAGNUM_WITH_FAAD2AUDIOIMPORTER=ON \
            -DMAGNUM_WITH_HARFBUZZFONT=ON \
            -DMAGNUM_WITH_ICOIMPORTER=ON \
            -DMAGNUM_WITH_JPEGIMAGECONVERTER=ON \
            -DMAGNUM_WITH_JPEGIMPORTER=ON \
            -DMAGNUM_WITH_KTXIMAGECONVERTER=ON \
            -DMAGNUM_WITH_KTXIMPORTER=ON \
            -DMAGNUM_WITH_LUNASVGIMPORTER=OFF \
            -DMAGNUM_WITH_MESHOPTIMIZERSCENECONVERTER=OFF \
            -DMAGNUM_WITH_MINIEXRIMAGECONVERTER=ON \
            -DMAGNUM_WITH_OPENEXRIMAGECONVERTER=ON \
            -DMAGNUM_WITH_OPENEXRIMPORTER=ON \
            -DMAGNUM_WITH_OPENGEXIMPORTER=ON \
            -DMAGNUM_WITH_PLUTOSVGIMPORTER=OFF \
            -DMAGNUM_WITH_PNGIMAGECONVERTER=ON \
            -DMAGNUM_WITH_PNGIMPORTER=ON \
            -DMAGNUM_WITH_PRIMITIVEIMPORTER=ON \
            -DMAGNUM_WITH_RESVGIMPORTER=OFF \
            -DMAGNUM_WITH_SPIRVTOOLSSHADERCONVERTER=ON \
            -DMAGNUM_WITH_SPNGIMPORTER=OFF \
            -DMAGNUM_WITH_STANFORDIMPORTER=ON \
            -DMAGNUM_WITH_STANFORDSCENECONVERTER=ON \
            -DMAGNUM_WITH_STBDXTIMAGECONVERTER=ON \
            -DMAGNUM_WITH_STBIMAGECONVERTER=ON \
            -DMAGNUM_WITH_STBIMAGEIMPORTER=ON \
            -DMAGNUM_WITH_STBRESIZEIMAGECONVERTER=ON \
            -DMAGNUM_WITH_STBTRUETYPEFONT=ON \
            -DMAGNUM_WITH_STBVORBISAUDIOIMPORTER=ON \
            -DMAGNUM_WITH_STLIMPORTER=ON \
            -DMAGNUM_WITH_TINYGLTFIMPORTER=ON \
            -DMAGNUM_WITH_UFBXIMPORTER=ON \
            -DMAGNUM_WITH_WEBPIMAGECONVERTER=ON \
            -DMAGNUM_WITH_WEBPIMPORTER=ON \
            "${extra_config[@]}" \
            ../${_realname}-${pkgver}
    ninja
}

package() {
    cd "${srcdir}"/build-${CARCH}
    DESTDIR="${pkgdir}" ninja install

    install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" \
        "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
